package com.bigstar.lolkor;

import java.io.IOException;
import java.io.StringReader;
import java.util.ArrayList;

import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserFactory;

import android.content.Context;
import android.util.Log;

public class ItemData {
	
	public static ArrayList<ItemTemplate> items = new ArrayList<ItemTemplate>();
	
	public static void load(Context context){
		String data = null;
		if(items.size() <= 0){
			try {
				data = Utils.getXMLFileFromAssets(context, "items.xml");
				PullParserFromXML(data);
			} catch (IOException e) {
			}	
		}
	}
	
	public static void PullParserFromXML(String data) {
	      try {
	    	  XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
	    	  factory.setNamespaceAware(true);
	    	  XmlPullParser xpp = factory.newPullParser();
	    	  xpp.setInput(new StringReader(data));
	    	  int eventType = xpp.getEventType();
	    	  ItemTemplate item = null;
	    	  while (eventType != XmlPullParser.END_DOCUMENT) {
	    		  if(eventType == XmlPullParser.START_TAG){
	    			  if(xpp.getName().equals("item")){
	    				  item = new ItemTemplate();
	    			  }else if(xpp.getName().equals("name_en")){
	    				  item.name_en = xpp.nextText();
	    			  }else if(xpp.getName().equals("name_kor")){
	    				  item.name_kor = xpp.nextText();
	    			  }else if(xpp.getName().equals("price")){
	    				  item.price = Integer.parseInt(xpp.nextText());
	    			  }else if(xpp.getName().equals("ap")){
	    				  item.ap = Integer.parseInt(xpp.nextText());
	    			  }else if(xpp.getName().equals("damage")){
	    				  item.damage = Integer.parseInt(xpp.nextText());
	    			  }else if(xpp.getName().equals("armor")){
	    				  item.armor = Integer.parseInt(xpp.nextText());
	    			  }else if(xpp.getName().equals("armor_pen")){
	    				  item.armor_pen = Integer.parseInt(xpp.nextText());
	    			  }else if(xpp.getName().equals("armor_pen_per")){
	    				  item.armor_pen_per = Integer.parseInt(xpp.nextText());
	    			  }else if(xpp.getName().equals("cooldown_reduction")){
	    				  item.cooldown_reduction = Integer.parseInt(xpp.nextText());
	    			  }else if(xpp.getName().equals("attack_speed")){
	    				  item.attack_speed = Integer.parseInt(xpp.nextText());
	    			  }else if(xpp.getName().equals("move_speed")){
	    				  item.move_speed = Integer.parseInt(xpp.nextText());
	    			  }else if(xpp.getName().equals("move_speed_per")){
	    				  item.move_speed_per = Integer.parseInt(xpp.nextText());
	    			  }else if(xpp.getName().equals("health")){
	    				  item.health = Integer.parseInt(xpp.nextText());
	    			  }else if(xpp.getName().equals("life_steal")){
	    				  item.life_steal = Integer.parseInt(xpp.nextText());
	    			  }else if(xpp.getName().equals("mana")){
	    				  item.mana = Integer.parseInt(xpp.nextText());
	    			  }else if(xpp.getName().equals("spell_vamp")){
	    				  item.spell_vamp = Integer.parseInt(xpp.nextText());
	    			  }else if(xpp.getName().equals("mana_regen")){
	    				  item.mana_regen = Float.parseFloat(xpp.nextText());
	    			  }else if(xpp.getName().equals("health_regen")){
	    				  item.health_regen = Integer.parseInt(xpp.nextText());
	    			  }else if(xpp.getName().equals("mr")){
	    				  item.mr = Integer.parseInt(xpp.nextText());
	    			  }else if(xpp.getName().equals("magic_pen")){
	    				  item.magic_pen = Integer.parseInt(xpp.nextText());
	    			  }else if(xpp.getName().equals("magic_pen_per")){
	    				  item.magic_pen_per = Integer.parseInt(xpp.nextText());
	    			  }else if(xpp.getName().equals("cri_chance")){
	    				  item.cri_chance = Integer.parseInt(xpp.nextText());
	    			  }else if(xpp.getName().equals("text")){
	    				  item.text = xpp.nextText();
	    			  }else if(xpp.getName().equals("unique")){
	    				  item.unique = xpp.nextText();
	    			  }else if(xpp.getName().equals("dodge")){
	    				  item.dodge = Integer.parseInt(xpp.nextText());
	    			  }
	    		  }else if(eventType == XmlPullParser.END_TAG){
	    			  if(xpp.getName().equals("item")){
	    				  items.add(item);
	    			  }
	    		  }
	    		  eventType = xpp.next();
	    	  }
	      } catch (Exception e) {
	    	  Log.i("eror", e.toString());
	      }
	}
	public static int[][][] itemOrder = { //아이템정보 순서 //FIXME Order
		{ //방어구
			{ //체력
				6,23,25,26,24,33,35,121,122,48,57,59,
				60,67,69,116,77,90,83,127,85,117,137,92,97,120,135,138,103,105,
				106,107,108,123,115					
			},
			{ //마법저항력
				15,28,38,50,65,69,73,77,80,91,
				94,95,97,120,133,128,110
			},
			{ //체력회복
				9,10,25,31,32,58,62,81,83,127,90,
				94,103,106
			},
			{//방어력
				11,25,27,36,32,42,139,62,68,70,77,79,
				127,89,91,92,98,106,109,113
			}

		},
		{ //공격무기
			{ //공격력
				6,18,26,134,121,40,42,139,59,61,64,73,70,72,118,
				75,140,76,81,84,86,89,96,124,141,101,125,104,
				108,128,123,112,113,114,115
			},
			{ //치명타
				7,17,29,34,51,63,66,140,89,96,99,
				114,115
			},
			{	//공격속도
				7,19,39,46,49,51,66,118,74,80,
				84,117,90,96,124,99,101,102,113,115
			},
			{	//체력흡수
				21,26,121,63,70,75,90,141,125,104,112
			}
		},
		{	//마법도구
			{	//주문력
				129,130,131,132,
				8,20,24,30,37,122,52,53,54,55,56,
				67,71,74,116,84,87,88,82,93,95,100,
				102,136,135,133,105,107,109,110,111,112,115
			},
			{ //재사용 시간 감소
				8,35,45,49,55,61,68,69,83,85,88,
				96,98,102,133,138,106
			},
			{ //마력
				16,41,56,60,68,76,97,120,98,100,105,
				110,115
			},
			{ //마력회복
				5,13,24,22,31,38,122,41,55,58,76,81,83,85,88,100,102,133
			}
		},
		{ //이동속도증가
			{
				12,36,39,43,44,45,47,50,51,83,
				94,96,136,99,110,115
			}
		},
		{ //소모품
			{
				1,2,3,4,6,7,8,14,126,142,143
			}
		}
};

public static int[][] builds_item = { //오더에서 -1  
	{},
	{},
	{},
	{},
	{21, 30, 80},
	{},
	{},
	{},
	{61, 31, 80},
	{30, 102, 93},
	//10
	{90, 35, 41, 76, 97, 105},
	{38, 42, 46, 44, 49, 43},
	{37, 54, 40},
	{},
	{49, 37, 68, 76, 90, 79},
	{55, 40, 59, 67},
	{50, 28, 62},
	{41, 58, 60, 63, 85, 80},
	{38, 98, 50, 48, 73},
	{29, 51, 53, 54, 55, 66},
	//20
	{89,62, 74, 103, 69,124}, 
	{84},
	{34, 32, 56, 58, 59, 66},
	{},
	{},
	{},
	{90, 91, 61, 78, 88, 67},
	{93, 96, 94, 64},
	{95},
	{87, 92},
	//30
	{82, 57},
	{126},
	{126,105},
	{88, 98, 113, 65},
	{82, 89, 84, 68},
	{},
	{94, 86, 104, 110, 109, 106},
	{132},
	{},
	{74, 80, 83, 112, 113, 85},
	//40
	{99, 75},
	{69, 112},
	{},
	{},
	{},
	{117, 79, 116, 123, 112},
	{},
	{102, 107, 91, 106},
	{101},
	{},
	//50
	{98, 114}, //50
	{111, 81},
	{},
	{},
	{101, 87, 132},
	{109, 114},
	{},
	{},
	{107, 114},
	{104, 96},
	//60
	{95},
	{105},
	{},
	{},
	{},
	{},
	{},
	{97},
	{},
	{},
	//70
	{110, 108},
	{113, 100, 103},
	{127},
	{},
	{111},
	{},
	{},
	{},
	{},
	{},
	//80
	{},
	{},
	{},
	{},
	{},
	{},
	{},
	{},
	{},
	{},
	//90
	{},
	{},
	{},
	{},
	{},
	{},
	{},
	{},
	{},
	{},
	//100
	{},
	{},
	{},
	{},
	{},
	{},
	{},
	{},
	{},
	{},
	//110
	{},
	{},
	{},
	{},
	{},
	{},
	{},
	{},
	{},
	{},
	//120
	{},
	{},
	{},
	{},
	{},
	{},
	{},
	{},
	{129,130,131},
	{},
	{},
	//130
	{},
	{},
	{},
	{},
	{},
	{},
	{},
	{},
	{},
	//140
	{},
	{},
	{},
};

public static int[][] requires_item = { //오더에서-1
	{},
	{},
	{},
	{},
	{},
	{},
	{},
	{},
	{},
	{},
	//10
	{},
	{},
	{},
	{},
	{},
	{},
	{},
	{},
	{},
	{},
	//20
	{},
	{4, 4},
	{},
	{},
	{},
	{},
	{},
	{},
	{16},
	{19},
	//30
	{4, 9},
	{10, 8},
	{22},
	{},
	{22},
	{11, 10},
	{},
	{12, 14},
	{11, 18},
	{},
	//40
	{15, 12},
	{10, 17},
	{11},
	{11},
	{11},
	{},
	{11},
	{},
	{18, 18},
	{11, 14},
	//50
	{16, 18},
	{19, 19},
	{36},
	{19},
	{12, 19},
	{15, 19},
	{22},
	{30},
	{22, 17},
	{22, 15},
	//60
	{17, 17},
	{26, 8},
	{16, 20},
	{17},
	{27},
	{33, 18},
	{22, 19},
	{15, 26},
	{34, 14},
	{20, 41},
	//70
	{},
	{},
	{17, 14},
	{18, 18, 19},
	{39, 20},
	{40, 17},
	{22, 14, 10},
	{45, 18},
	{10, 26},
	{45, 14},
	//80
	{39, 17, 4, 8},
	{36, 51},
	{34, 30},
	{36, 39},
	{34, 22, 21},
	{39, 17},
	{36, 19},
	{29, 54},
	{26, 33},
	{34, 18, 20},
	//90
	{14, 10, 26},
	{26, 47},
	{29, 36},
	{9, 9, 27},
	{36, 27},
	{28, 60},
	{27, 59},
	{10, 10, 67},
	{33, 50, 18},
	{40, 36},
	//100
	{71, 18},
	{48, 54},
	{47, 22, 9},
	{71, 20},
	{59, 36},
	{32, 61, 10},
	{36, 19, 47},
	{58, 47},
	{26, 70},
	{14, 55, 36},
	//110
	{36, 70},
	{74, 51},
	{41, 39, 45},
	{71, 39, 33},
	{50, 55, 58},
	{19, 19, 34},
	{45, 22},
	{17, 45},
	{8, 8},
	{27, 59},
	//120
	{},
	{},
	{58, 71},
	{39, 45},
	{20, 71},
	{},
	{32,31},
	{72, 39},
	{},
	{128},
	//130
	{128},
	{128},
	{19, 37, 54},
	{},
	{29,66},
	{70,26},
	{47,22},
	{32,60},
	{41},
	{33,17},
	//140
	{74},
	{},
	{},
};
}
